package cn.itsource.romate.impl;

import cn.itsource.pojo.api.AddLogin;
import cn.itsource.pojo.domain.Login;
import cn.itsource.result.R;
import cn.itsource.romate.api.LoginApi;
import cn.itsource.service.ILoginService;
import cn.itsource.utils.NameUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * 📖：beishan
 * 🗓️：2024/3/29 11:28
 * =====================
 * LoginApi的controller层
 */
@RestController
public class LoginApiImpl implements LoginApi {

    @Autowired
    private ILoginService loginService;

    @Override
    public R addLogin(AddLogin addLogin) {
        Login login = new Login();
        login.setId(addLogin.getId());
        login.setUsername(addLogin.getUsername());
        login.setType(addLogin.getType());
        login.setAvatar("");
        //调用工具类 随机生成
        String adminName = NameUtil.getAdminName();
        login.setNickName(adminName);
        login.setOpenId(addLogin.getOpenId());
        login.setName(addLogin.getPhone());
        login.setPhone(addLogin.getPhone());
        login.setCreateTime(new Date());

        loginService.save(login);

        return R.success();
    }

    /**
     * 审核成功后  将名字添加到登录表中
     * @param id login id
     * @param name 司机名字
     * @return
     */
    @Override
    public R updLogin(Long id, String name) {
        Login login = loginService.getById(id);
        login.setName(name);
        loginService.updateById(login);
        return R.success();
    }




}
